<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>商品审核</title>
    <link rel="icon" href="favicon.ico" type="image/x-icon"/>
<#include "../template/template_editPage.ftl">
<#include "../template/include/assign.ftl">
<#include "../template/include/source.ftl">
    <link href="${web_static}/admin/css/list.css" rel="stylesheet" type="text/css"/>


    <script type="text/javascript">
        function disable() {
            $("input[type='button']").attr('disabled', 'disabled');
            $("input[type='submit']").attr('disabled', 'disabled');
            $("input[type='text']").attr('disabled', 'disabled');
        }


        $().ready(function () {



        <#if actionErrors?? && (actionErrors?size > 0)>
            $.dialog({type:"warn", content:"<#list errorMessages as list>${list}<br></#list>",
                modal:true, autoCloseTime:3000});
            disable();
        </#if>

        });

        function validateAddGoodsForm(){
            var $validateErrorContainer = $("#validateErrorContainer");
            var $validateErrorLabelContainer = $("#validateErrorContainer ul");
            var $validateForm = $("#addGoodsForm");
            var $tab = $("#tab");

            // Tab效果
            $tab.tabs(".tabContent", {
                tabs:"input"
            });

            // 表单验证
            $validateForm.validate({
                errorContainer:$validateErrorContainer,
                errorLabelContainer:$validateErrorLabelContainer,
                wrapper:"li",
                errorClass:"validateError",
                ignoreTitle:true,
                rules:{
                    "goods.goodsCategoryId":{
                        required:true
                    },
                    "commonSalePrice":{
                        required:true
                    },
                    "goods.goodsDescription":{
                        maxlength:2000
                    },
                    "goods.stateMent":{
                        maxlength:2000
                    },
                    "goods.remark":{
                        maxlength:500
                    }
                },
                messages:{
                    "goods.goodsCategoryId":{
                        required:"请填写商品品牌编号！"
                    },
                    "commonSalePrice":{
                        required:"请填写商品默认售价！"
                    },
                    "goods.goodsDescription":{
                        maxlength:"备注内容必须要小于等于2000"
                    },
                    "goods.stateMent":{
                        maxlength:"备注内容必须要小于等于2000"
                    },
                    "goods.remark":{
                        maxlength:"备注内容必须要小于等于500"
                    }
                },
                submitHandler:function (form) {
                    $(form).find(":submit").attr("disabled", true);
                    form.submit();
                }
            });
        }

        function query(goodsCategoryId) {
            var data = $('#queryBrand').serialize() + "&goodsState=1&goodsCategoryId=" + goodsCategoryId;
            $.ajax({
                type:"POST",
                async:false,
                url:"${web_base}/game/audit!query.htm",
                data:data,
                success:function (msg) {
                    var html = "";
                    $('#goodsListTbody').html(html);
                    var result = eval("(" + msg + ")");
                    if (result != undefined && result != '' && result.length > 0) {
                        $.each(result, function (i, n) {
                            var obj = n;
                            html = html + "<tr><td>" +
                                    obj.goodsId +
                                    "</td><td>" +
                                    obj.goodsCategoryId +
                                    "</td><td>" +
                                    obj.goodsName +
                                    "</td><td>" +
                                    tranMoney(obj.commonSalePrice) +
                                    "</td><td>" +
                                    tranMoney(obj.goodsMoney) +
                                    "</td><td>" +
                                    tranGoodsState(obj.goodsState) +
                                    "</td><td>" +
                                    tranRechargeMode(obj.rechargeMode) +
                                    "</td></tr>";
                        });
                        $("#noGoods").hide();
                        $('#goodsListTbody').html(html);
                    }
                    else {
                        $("#noGoods").show();
                    }
                }
            });
        }

        function tranGoodsState(state) {
            if (state == '1') {
                return '上架';
            } else {
                return '下架';
            }
        }
        function tranRechargeMode(mode) {
            if (mode == '2') {
                return '直充';
            } else {
                return '卡充';
            }
        }
        function tranGoodsEnable(enable) {
            if (enable == '0') {
                return '禁用';
            } else {
                return '启用';
            }
        }
        function tranMoney(money) {
            if (money != undefined && money != null && money != '') {
                var f = money / 1000;
                var s = f.toString();
                var rs = s.indexOf('.');
                if (rs < 0) {
                    rs = s.length;
                    s += '.';
                }
                while (s.length <= rs + 3) {
                    s += '0';
                }
                return s;
            }
            return '';

        }
        function show(){
            $('#addGoodsForm').show();
        }
        function hide(){
            $('#addGoodsForm').hide();
            $('#validateErrorContainer').hide();
        }

        function checkPrice() {
            $("#priceSpan").html('');
            var e = /^(([1-9]\d{0,5})|0)(\.\d{1,3})?$/;
            var blsx = $("#price").val();
            if (!e.test(blsx)) {
                $("#priceSpan").html('价格格式不正确！(例：0.000)');
                return false;
            }
            else {
                return true;
            }
        }

        function submitForm() {

            validateAddGoodsForm();
            if (!$('#addGoodsForm').valid()) {
                return;
            }

            var data = $('#addGoodsForm').serialize() + "&supplyId=${supplyId!}&originalGoodsId=${originalGoodsId!}";
            $.ajax({
                type:"POST",
                async:false,
                url:"${web_base}/game/audit!saveGoods.htm",
                data:data,
                success:function (msg) {
                    if (msg != undefined && msg != '') {
                        var result = eval("(" + msg + ")");
                        var html = "";
                        var id = result.id;
                        var errorMsg = result.errorMsg;
                        var goods = result.goods;
                        if (id != undefined && id != null && id != '') {
                            if(goods!=undefined && goods != null){
                                html = "<tr><td>" +
                                        goods.goodsId +
                                        "</td><td>" +
                                        goods.goodsCategoryId +
                                        "</td><td>" +
                                        goods.goodsName +
                                        "</td><td>" +
                                        tranMoney(goods.commonSalePrice) +
                                        "</td><td>" +
                                        tranMoney(goods.goodsMoney) +
                                        "</td><td>" +
                                        tranGoodsState(goods.goodsState) +
                                        "</td><td>" +
                                        tranRechargeMode(goods.rechargeMode) +
                                        "</td></tr>";
                            }
                            $('#goodsListTbody').html(html);
                            $("#noGoods").hide();
                            $.dialog({type:"success", content:"您的操作已成功.", modal:true, autoCloseTime:5000});
                            $('#goodsId').val(id);
                            $('#addGoodsForm').hide();
                        }else
                        {
                            $.dialog({type:"warn", content:errorMsg, modal:true, autoCloseTime:5000});
                        }
                    }
                }
            });

        }

    </script>
</head>
<body class="list">
<div class="body">
<div class="listBar">
    <h1><span class="icon">&nbsp;</span><#if supplyId=="20121000">殴飞商品审核<#elseif supplyId=="20121001">
        坚果商品审核<#elseif supplyId=="20121002">腾讯商品审核</#if></h1>
</div>
<table class="listTable">
<#if nutsNet??>
    <tr>
        <th width="50%">
            <span class="sort" name="name">商品名称</span>
        </th>
        <th width="15%">
            <span class="sort" name="unitPrice">进价(元)</span>
        </th>
        <th width="15%">
            <span class="sort" name="parvalue">商品面额(元)</span>
        </th>
        <th width="20%">
            <span class="sort" name="isAudit">是否已审核</span>
        </th>
    </tr>
    <tr>
        <td width="50%">
        ${(nutsNet.name)!}
        </td>
        <td width="15%">
        ${(nutsNet.unitPrice)!}
        </td>
        <td width="15%">
        ${(nutsNet.parvalue)!}
        </td>
        <td width="20%">
            <#if nutsNet.isAudit?? && nutsNet.isAudit=="0">
                未审核
            <#elseif nutsNet.isAudit?? && nutsNet.isAudit=="1">
                已审核
            </#if>
        </td>
    </tr>
<#elseif ohFly??>
    <tr>
        <th width="50%">
            <span class="sort" name="goodsName">商品名称</span>
        </th>
        <th width="15%">
            <span class="sort" name="goodsInPrice">进价(元)</span>
        </th>
        <th width="15%">
            <span class="sort" name="parValue">商品面额(元)</span>
        </th>
        <th width="20%">
            <span class="sort" name="isAudit">是否已审核</span>
        </th>
    </tr>
    <tr>
        <td width="50%">
        ${(ohFly.goodsName)!}
        </td>
        <td width="15%">
        ${(ohFly.goodsInPrice)!}
        </td>
        <td width="15%">
        ${(ohFly.parValue)!}
        </td>
        <td width="20%">
            <#if ohFly.isAudit?? && ohFly.isAudit=="0">
                未审核
            <#elseif  ohFly.isAudit?? && ohFly.isAudit=="1">
                已审核
            </#if>
        </td>
    </tr>
<#elseif tencent??>
    <tr>
        <th width="50%">
            <span class="sort" name="productName">产品名称</span>
        </th>
        <th width="25%">
            <span class="sort" name="inPrice">产品进价(元)</span>
        </th>
        <th width="25%">
            <span class="sort" name="isAudit">是否已审核</span>
        </th>
    </tr>
    <tr>
        <td width="50%">
        ${(tencent.productName)!}
        </td>
        <td width="25%">
        ${(tencent.inPrice)!}
        </td>
        <td width="25%">
            <#if tencent.isAudit?? && tencent.isAudit=="0">
                未审核
            <#elseif tencent.isAudit?? && tencent.isAudit=="1">
                已审核
            </#if>
        </td>
    </tr>
</#if>
</table>
<form id="inputForm" class="validate" action="${web_base}/game/audit!list.htm" method="post">
    <div class="listBar">
        <h1><span class="icon">&nbsp;</span>商品品牌信息:</h1>
    </div>
    <table class="listTable">
        <tr>
            <th>
                <span class="sort" name="goodsCategoryId">商品品牌代码</span>
            </th>
            <th>
                <span class="sort" name="gameName">商品品牌名称</span>
            </th>
            <th width="80">&nbsp;操&nbsp;&nbsp;&nbsp;作
            <th/>
        </tr>
    <#if brandList?? && (brandList?size gt 0)>
        <#list brandList as obj>
            <tr>
                <td>
                ${(obj.goodsCategoryId)!}
                </td>
                <td>
                ${(obj.gameName)!}
                </td>
                <td width="80">
                    <div class="operateBar">
                        <input type="button" class="addButton" id="queryBrand"
                               onclick="query('${(obj.goodsCategoryId)!}');"
                               value="查询"/>
                    </div>
                </td>
            </tr>
        </#list>
    <#elseif brand??>
        <tr>
            <td>
            ${(brand.goodsCategoryId)!}
            </td>
            <td>
            ${(brand.gameName)!}
            </td>
            <td width="80">
                <div class="operateBar">
                    <input type="button" class="addButton" id="queryBrand"
                           onclick="query('${(obj.goodsCategoryId)!}');"
                           value="查询"/>
                </div>
            </td>
        </tr>
    </#if>
    </table>
<#if brandList?? && (brandList?size <= 0)>
    <div class="noRecord">
        没有找到任何记录!
    </div>
</#if>
</form>
<div class="operateBar">
    <input type="button" class="addButton"
           onclick="location.href='${web_base}/game/audit!saveBrand.htm?originalGoodsId=${originalGoodsId!}&supplyId=${supplyId!}'"
           value="新增品牌"/>说明：若以上查询列表中没有此品牌，则需新增，否则不需新增！
</div>

<div class="listBar">
    <h1><span class="icon">&nbsp;</span>商品信息</h1>
</div>
<table class="listTable" id="goodsList">
    <thead>
    <tr>
        <th>
            <span class="sort" name="goodsId">商品编号</span>
        </th>
        <th>
            <span class="sort" name="goodsCategoryId">品牌编号</span>
        </th>
        <th>
            <span class="sort" name="goodsName">商品名称</span>
        </th>
        <th>
            <span class="sort" name="commonSalePrice">默认售价(元)</span>
        </th>
        <th>
            <span class="sort" name="goodsMoney">商品面值(元)</span>
        </th>
        <th>
            <span class="sort" name="goodsState">商品状态</span>
        </th>
        <th>
            <span class="sort" name="rechargeMode">充值方式</span>
        </th>
    </tr>
    </thead>
    <tbody id="goodsListTbody">
    </tbody>
</table>
<div class="noRecord" id="noGoods" style="display: none;">
    没有找到任何记录!
</div>
<div class="operateBar">
    <input type="button" class="addButton" onclick="show();" value="新增商品"/>
    说明：商品新增成功后会把此新增的商品编号输入到，商品供应操作下的商品编号的输入框中！
</div>
<div style="display: none;" id="validateErrorContainer" class="validateErrorContainer">
    <div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
    <ul id="ul"></ul>
</div>
<form id="addGoodsForm" class="validate" action="" method="post" onsubmit="return false;" style="display: none;">
    <div class="listBar">
        <h1><span class="icon">&nbsp;</span>商品基本信息</h1>
    </div>
    <table class="inputTable tabContent">
        <tr>
            <th>
                商品品牌编号:
            </th>
            <td>
                <input type="text" name="goods.goodsCategoryId" class="formText {required: true}" value=""/>
                <label class="requireField">*</label>
            </td>
        </tr>
        <tr>
            <th>
                默认售价:(元)
            </th>
            <td>
                <input type="text" id="price" name="commonSalePrice" class="formText {required: true}" value="" onblur="checkPrice();"/>
                <label class="requireField">*</label>
                <span id="priceSpan" style="color: red"></span>
            </td>
        </tr>
        <tr>
            <th>
                商品描述:
            </th>
            <td>
                <textarea name="goods.goodsDescription" class="formTextarea"  style="width: 180px;height: 70px;"></textarea>
            </td>
        </tr>
        <tr>
            <th>
                游戏说明:
            </th>
            <td>
                <textarea name="goods.stateMent" class="formTextarea"  style="width: 180px;height: 70px;"></textarea>
            </td>
        </tr>
        <tr>
            <th>
                备注：
            </th>
            <td>
                <textarea name="goods.remark" class="formTextarea"  style="width: 180px;height: 70px;"></textarea>
            </td>
        </tr>
    </table>
    <div class="buttonArea">
        &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="formButton" value="添  加" hidefocus="true" onclick="submitForm();"/>&nbsp;&nbsp;
        <input type="button" class="formButton" onclick="hide(); " value="返  回" hidefocus="true"/>
    </div>
</form>

<form id="inputForm3" class="validate"
      action="${web_base}/game/audit!saveGoodSupply.htm?originalGoodsId=${originalGoodsId!}&supplyId=${supplyId!}"
      method="post">
    <div class="listBar">
        <h1><span class="icon">&nbsp;</span>商品供应操作</h1>
    </div>
    <div class="operateBar">
        商品编号：<input type="text" name="goodsId" id="goodsId" class="formText {required: true}" value=""/>
        <input type="submit" class="addButton" value="提交"/>
    </div>
</form>

</div>
</body>
</html>